package com.robot.mvvm.vm

import android.app.Application
import api.UserServiceFactory
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.configs.PrefsManager
import com.robot.base.model.UserInfoBean
import me.goldze.mvvmhabit.http.BaseResponse

class MainViewModel(application: Application) : GLBaseViewModel(application) {


    fun start() {
        getLoginUser()
    }

    private fun getLoginUser() {
        UserServiceFactory.getLoginUser()
            .subscribe(object : AbstractViewModelSubscriber<BaseResponse<UserInfoBean>>(this) {
                override fun onNext(t: BaseResponse<UserInfoBean>) {
                    PrefsManager.saveUserInfo(t.data)
                }
            })
    }
}